﻿using AntMovement.Core;
using AntMovement.Core.Attributes;
using AntMovement.Core.Entity;
using AntMovement.Core.Hardware;
using AntMovement.Core.IParameter;
using AntMovement.Core.Logic;
using AntMovement.Core.Logic.Base;
using AntMovement.Core.Model;
using AntMovement.Parameter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AntMovement.Handle.FPCAutomaticPlateSetting
{
    [FlowAttributes(nameof(ModuleMotion), 4)]
    public class ModuleMotion : TaskBase
    {
        #region 轴变量
        private AxisMotion _axisX = default, _axisY = default;
        private AxisMotion[] _axisZ = default;
        private AxisMotion[] _axisR = default;

        private Axis _axisEntityY;
        private Axis _axisEntityX;
        private Axis[] _axisEntityZ;
        private Axis[] _axisEntityR;
        #endregion

        #region 上升沿
        #endregion

        #region 定时器
        private Ton _ton1 = new Ton();
        private Ton _ton2 = new Ton();
        #endregion

        #region 点位
        private PointPositionInfoModel _推料盘位;
        private PointPositionInfoModel _收料盘位;
        private PointPositionInfoModel _码垛1起点位;
        private PointPositionInfoModel _码垛2起点位;
        #endregion

        #region 输入点

        #endregion

        #region 输出点

        #endregion

        #region 单控
        private ISingleControl[] _Z轴吸嘴;
        private ISingleControl[] _Z轴吸嘴大气;
        private ISingleControl _上料直震;
        #endregion

        #region 报警变量
        #endregion

        #region 私有变量
        private HoldParameter _holdParameter;
        private string _pointname = string.Empty;
        private IAirCylinder _推盘升降气缸;
        private IAirCylinder _收盘升降;
        private long _xp = 0, _yp = 0, _zp = 0;
        private long[] _rp = new long[3];
        private int _nozzleCount = 0;
        private int _nozzleIndex = 0;
        private bool[] _吸嘴有料信号 = new bool[3];
        private double[] _zH = new double[] { 35, 37, 36 };
        private double[] _zLP = new double[] { 38.5, 40, 41 };
        private long _avoidY = 0;
        #endregion
        public ModuleMotion(ITemporaryParameter temporary, IIOParameter iop, IAxisParameter axisp, IDialogHost dialogHost, ILog log, IHoldParameter holdParameter)
            : base(temporary, iop, axisp, dialogHost, log)
        {
            _axisZ = new AxisMotion[3];
            for (int i = 1; i < 4; i++)
            {
                _axisZ[i - 1] = axisp.GetAxisMotion($"Z轴{i}#");
            }
            _axisR = new AxisMotion[3];
            for (int i = 1; i < 4; i++)
            {
                _axisR[i - 1] = axisp.GetAxisMotion($"R轴{i}#");
            }
            _Z轴吸嘴 = new ISingleControl[3];
            for (int i = 1; i < 4; i++)
            {
                _Z轴吸嘴[i - 1] = iop.GetSingleControl($"{i}#吸嘴", "真空");
            }
            _Z轴吸嘴大气 = new ISingleControl[3];
            for (int i = 1; i < 4; i++)
            {
                _Z轴吸嘴大气[i - 1] = iop.GetSingleControl($"{i}#吸嘴大气", "大气");
            }
            _上料直震 = iop.GetSingleControl("直震", "电机");
            _axisEntityX = axisp.GetAxisEntity("X轴");
            _axisEntityY = axisp.GetAxisEntity("Y轴");
            _axisEntityZ = new Axis[3];
            for (int i = 1; i < 4; i++)
            {
                _axisEntityZ[i - 1] = axisp.GetAxisEntity($"Z轴{i}#");
            }
            _axisEntityR = new Axis[3];
            for (int i = 1; i < 4; i++)
            {
                _axisEntityR[i - 1] = axisp.GetAxisEntity($"R轴{i}#");
            }

            _推盘升降气缸 = iop.GetAirCylinder("推盘升降");
            _收盘升降 = iop.GetAirCylinder("收盘升降");
            _axisX = axisp.GetAxisMotion("X轴");
            _axisY = axisp.GetAxisMotion("Y轴");

            _推料盘位 = axisp.GetPointPosition("推料盘位");
            _收料盘位 = axisp.GetPointPosition("收料盘位");
            _码垛1起点位 = axisp.GetPointPosition("码垛1起点位");
            _码垛2起点位 = axisp.GetPointPosition("码垛2起点位");
            _holdParameter = (HoldParameter)holdParameter;
            _avoidY = DistanceToPulse(500, _axisEntityY);
        }

        public override void EmergencyStop()
        {

        }

        public override void Handle()
        {
            _zH[0] = _holdParameter.ZAxisWithdrawOne;
            _zH[1] = _holdParameter.ZAxisWithdrawTwo;
            _zH[2] = _holdParameter.ZAxisWithdrawThree;
            _zLP[0] = _holdParameter.ZAxisPlaceOne;
            _zLP[1] = _holdParameter.ZAxisPlaceTwo;
            _zLP[2] = _holdParameter.ZAxisPlaceThree;
            if (_temporary.SystemStatus.Auto)
            {
            }
            if (SignalOn(0))
            {
                _推盘升降气缸.Auto_Close = true;
                _推盘升降气缸.Auto_Open = !_推盘升降气缸.Auto_Close;
                if (_推盘升降气缸.Reach_Close)
                {
                    StrokeMatchingSpeed(0, 0.1, _axisEntityX, 0, 0);
                    //StrokeMatchingSpeed(500, 0.06, _axisEntityY, 0, 0);
                    NextStep(2);
                }
            }
            if (SignalOn(2))
            {
                _axisZ[0].Move(0, 30000);
                _axisZ[1].Move(0, 30000);
                _axisZ[2].Move(0, 30000);
                if (_axisZ[0].ArrivalLocation && _axisZ[1].ArrivalLocation && _axisZ[2].ArrivalLocation)
                {
                    NextStep(3);
                }
            }
            if (SignalOn(5))
            {
                if (PointPositionMove(0, _avoidY))
                {
                    NextStep(5);
                }
            }
            #region 请求拍照定位
            if (SignalOn(10))
            {
                if (!_temporary.Orientation)
                {
                    if (_temporary.BackOrientation.Count == 0 || _temporary.BackOrientation.Count < (_吸嘴有料信号.Count(x => !x) * 3))
                    {
                        NextStep(5);
                    }
                    else
                    {
                        NextStep(20);
                    }
                }
            }
            if (SignalOn(15))
            {
                _temporary.Status_模组运动.SafetyPosition = true;
                NextStep(5);
            }
            if (SignalOn(20))
            {
                if (_temporary.Status_模组运动.Permit_TakeMaterials)
                {
                    NextStep();
                }
            }
            #endregion
            #region 取料业务
            if (SignalOn(30))
            {
                _axisZ[0].Move(0, 30000);
                _axisZ[1].Move(0, 30000);
                _axisZ[2].Move(0, 30000);
                if (_axisZ[0].ArrivalLocation && _axisZ[1].ArrivalLocation && _axisZ[2].ArrivalLocation)
                {
                    NextStep();
                }
            }
            if (SignalOn(40))
            {
                for (int i = 0; i < 3; i++)
                {
                    if (!_吸嘴有料信号[i])
                    {
                        _nozzleIndex = i;
                        break;
                    }
                }
                if (_吸嘴有料信号.Any(x => !x))
                {
                    NextStep();
                }
                else
                {
                    _step = 90;
                }
            }
            if (SignalOn(50))
            {
                var nozzles = _temporary.BackOrientation.Where(x => x.Name == $"{(_nozzleIndex + 1)}#").ToArray();
                if (nozzles != null && nozzles.Length > 0)
                {
                    var nozzle = GetBackOrientation(nozzles);
                    _xp = DistanceToPulse(nozzle.X, _axisEntityX);
                    _yp = DistanceToPulse(nozzle.Y, _axisEntityY);
                    _rp[_nozzleIndex] = DistanceToPulse(nozzle.R, _axisEntityR[_nozzleIndex]);
                    _zp = DistanceToPulse(_zH[_nozzleIndex], _axisEntityZ[_nozzleIndex]);
                    StrokeMatchingSpeed(_zH[_nozzleIndex], 0.1, _axisEntityZ[_nozzleIndex], 0, 0);
                    StrokeMatchingSpeed(nozzle.X, 0.07, _axisEntityX, 0, 0);
                    if (!_temporary.ShieldYAxisVariableSpeed)
                    { StrokeMatchingSpeed(nozzle.Y, 0.05, _axisEntityY, 0, 0); }
                    var models = _temporary.BackOrientation.Where(x => x.Index == nozzle.Index).ToArray();
                    if (models != null && models.Length > 0)
                    {
                        for (int i = 0;i < models.Length; i++) _temporary.BackOrientation.Remove(models[i]);
                    }
                    NextStep(5);
                }
                else
                {
                    _temporary.Status_模组运动.Permit_TakeMaterials = false;
                    _step = 0;
                }
            }
            if (SignalOn(55))
            {
                if (PointPositionMove(_xp, _yp, false))
                {
                    NextStep(5);
                }
            }
            if (SignalOn(60))
            {
                _axisZ[_nozzleIndex].Move(_zp, 30000, bl:false);
                if (_axisZ[_nozzleIndex].ArrivalLocation)
                {
                    NextStep();
                }
            }
            if (SignalOn(70))
            {
                _Z轴吸嘴[_nozzleIndex].Auto_Close = false;
                _Z轴吸嘴[_nozzleIndex].Auto_Open = !_Z轴吸嘴[_nozzleIndex].Auto_Close;
                if (_Z轴吸嘴[_nozzleIndex].IOStatus)
                {
                    _zp = DistanceToPulse(_axisEntityZ[_nozzleIndex].UnitConversion.ActualPosition - 8, _axisEntityZ[_nozzleIndex]);
                    _吸嘴有料信号[_nozzleIndex] = true;
                    StrokeMatchingSpeed(_axisEntityZ[_nozzleIndex].UnitConversion.ActualPosition - 8, 0.1, _axisEntityZ[_nozzleIndex], 0, 0);
                    NextStep();
                }
            }
            if (SignalOn(80))
            {
                _axisZ[_nozzleIndex].Move(_zp, 30000, bl: false);
                if (_axisZ[_nozzleIndex].ArrivalLocation)
                {
                    StrokeMatchingSpeed(0, 0.1, _axisEntityZ[_nozzleIndex], 0, 0);
                    NextStep(5);
                }
            }
            if (SignalOn(85))
            {
                _axisZ[_nozzleIndex].Move(0, 30000, bl: false);
                _axisR[_nozzleIndex].Move(_rp[_nozzleIndex], 30000);
                _step = 40;
            }
            #endregion
            #region 摆盘业务
            if (SignalOn(90))
            {
                _axisZ[0].Move(0, 30000);
                _axisZ[1].Move(0, 30000);
                _axisZ[2].Move(0, 30000);
                if (_axisZ[0].ArrivalLocation && _axisZ[1].ArrivalLocation && _axisZ[2].ArrivalLocation)
                {
                    NextStep();
                }
            }
            if (SignalOn(100))
            {
                if (_holdParameter.CurrentDiskPosition == 1 && (_holdParameter.CurrentStackingLine == (_holdParameter.XCount - 1) || _holdParameter.CurrentStackingLine == (_holdParameter.XCount - 2)))
                {
                    if (_吸嘴有料信号[1] || _吸嘴有料信号[2])
                    {
                        for (int i = 1; i < 3; i++)
                        {
                            if (_吸嘴有料信号[i])
                            {
                                _nozzleCount = i;
                                break;
                            }
                        }
                        NextStep(5);
                    }
                    else
                    {
                        _step = 10;
                    }
                }
                else if (_holdParameter.CurrentDiskPosition == 0 && _holdParameter.CurrentStackingLine == 0)
                {
                    if (_吸嘴有料信号[0] || _吸嘴有料信号[1])
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            if (_吸嘴有料信号[i])
                            {
                                _nozzleCount = i;
                                break;
                            }
                        }
                        NextStep(5);
                    }
                    else
                    {
                        _step = 10;
                    }
                }
                else
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (_吸嘴有料信号[i])
                        {
                            _nozzleCount = i;
                            break;
                        }
                    }
                    NextStep(5);
                }
            }
            if (SignalOn(105))
            {
                if (_Z轴吸嘴[_nozzleCount].Signal)
                { 
                    NextStep(5);
                }
                else
                {
                    _Z轴吸嘴[_nozzleCount].Auto_Close = true;
                    _Z轴吸嘴[_nozzleCount].Auto_Open = !_Z轴吸嘴[_nozzleCount].Auto_Close;
                    _吸嘴有料信号[_nozzleCount] = false;
                    _axisR[_nozzleCount].ClearPos();
                    NextStep(1);
                }
            }
            if (SignalOn(106))
            {
                _axisR[_nozzleCount].Move(0, 30000);
                if (_axisR[_nozzleCount].ArrivalLocation)
                {
                    NextStep(4);
                }
            }
            if (SignalOn(110))
            {
                if (_temporary.Status_料盘固定.SafetyPosition)
                {
                    _zp = DistanceToPulse(_zLP[_nozzleCount], _axisEntityZ[_nozzleCount]);
                    double deviation = _nozzleCount == 0 ? 0.3D : 0;
                    if (_holdParameter.CurrentDiskPosition == 0)
                    {
                        _xp = _码垛1起点位.XPulse - DistanceToPulse((_holdParameter.CurrentStackingLine * _holdParameter.MaterialSpacingLine), _axisEntityX) + DistanceToPulse(_nozzleCount * 45D + deviation, _axisEntityX);
                        _yp = _码垛1起点位.YPulse + DistanceToPulse((_holdParameter.CurrentStackingColumn * _holdParameter.MaterialSpacingColumn), _axisEntityY);
                    }
                    else
                    {
                        _xp = _码垛2起点位.XPulse - DistanceToPulse((_holdParameter.CurrentStackingLine * _holdParameter.MaterialSpacingLine), _axisEntityX) + DistanceToPulse(_nozzleCount * 45D + deviation, _axisEntityX);
                        _yp = _码垛2起点位.YPulse + DistanceToPulse((_holdParameter.CurrentStackingColumn * _holdParameter.MaterialSpacingColumn), _axisEntityY);
                    }
                    StrokeMatchingSpeed(_zLP[_nozzleCount], 0.1, _axisEntityZ[_nozzleCount], 0, 0);
                    StrokeMatchingSpeed(PulseToDistance(_xp, _axisEntityX), 0.07, _axisEntityX, 0, 0);
                    if (!_temporary.ShieldYAxisVariableSpeed)
                    { StrokeMatchingSpeed(PulseToDistance(_yp, _axisEntityY), 0.05, _axisEntityY, 0, 0); }
                    NextStep();
                }
            }
            if (SignalOn(120))
            {
                _axisR[_nozzleCount].Move(_rp[_nozzleCount], 30000);
                if (PointPositionMove(_xp, _yp) && _axisR[_nozzleCount].ArrivalLocation)
                {
                    _temporary.Status_模组运动.SafetyPosition = true;
                    _temporary.Status_模组运动.Permit_TakeMaterials = false;
                    _axisR[_nozzleCount].ClearPos();
                    NextStep(5);
                }
            }
            if (SignalOn(125))
            {
                _axisR[_nozzleCount].Move(0, 30000);
                if (_axisR[_nozzleCount].ArrivalLocation)
                {
                    NextStep(5);
                }
            }
            if (SignalOn(130))
            {
                if (_axisEntityZ[_nozzleCount].UnitConversion.ActualPosition > 15)
                {
                    _Z轴吸嘴[_nozzleCount].Auto_Close = true;
                    _Z轴吸嘴[_nozzleCount].Auto_Open = !_Z轴吸嘴[_nozzleCount].Auto_Close;
                }
                _axisZ[_nozzleCount].Move(_zp, 30000, bl: false);
                if (_axisZ[_nozzleCount].ArrivalLocation)
                {
                    NextStep();
                }
            }
            if (SignalOn(140))
            {
                _Z轴吸嘴大气[_nozzleCount].Auto_Open = true;
                _Z轴吸嘴大气[_nozzleCount].Auto_Close = !_Z轴吸嘴大气[_nozzleCount].Auto_Open;
                if (!_Z轴吸嘴[_nozzleCount].IOStatus && !_Z轴吸嘴[_nozzleCount].Signal)
                {
                    _zp = DistanceToPulse(_axisEntityZ[_nozzleCount].UnitConversion.ActualPosition - 12, _axisEntityZ[_nozzleCount]);
                    _吸嘴有料信号[_nozzleCount] = false;
                    StrokeMatchingSpeed(_axisEntityZ[_nozzleCount].UnitConversion.ActualPosition - 12, 0.1, _axisEntityZ[_nozzleCount], 0, 0);
                    NextStep();
                }
            }
            if (SignalOn(150))
            {
                _axisZ[_nozzleCount].Move(_zp, 30000, bl: false);
                if (_axisZ[_nozzleCount].ArrivalLocation)
                {
                    _Z轴吸嘴大气[_nozzleCount].Auto_Open = false;
                    _Z轴吸嘴大气[_nozzleCount].Auto_Close = !_Z轴吸嘴大气[_nozzleCount].Auto_Open;
                    StrokeMatchingSpeed(0, 0.1, _axisEntityZ[_nozzleCount], 0, 0);
                    NextStep();
                }
            }
            if (SignalOn(160))
            {
                if (_holdParameter.CurrentStackingLine == (_holdParameter.XCount - 1))
                {
                    _holdParameter.CurrentStackingLine = 0;
                    if (_holdParameter.CurrentStackingColumn == (_holdParameter.YCount - 1))
                    {
                        _holdParameter.CurrentStackingColumn = 0;
                        if (_holdParameter.CurrentDiskPosition == 1)
                        {
                            _holdParameter.CurrentDiskPosition = 0;
                            _temporary.Status_Z轴.FullMaterial = true;
                        }
                        else
                        {
                            _holdParameter.CurrentDiskPosition++;
                        }
                    }
                    else
                    {
                        _holdParameter.CurrentStackingColumn++;
                    }
                }
                else
                {
                    _holdParameter.CurrentStackingLine++;
                }
                if (_temporary.Status_Z轴.FullMaterial)
                {
                    _step = 320;
                    _nozzleCount = 0;
                }
                else
                {
                    _axisZ[_nozzleCount].Move(0, 30000, bl: false);
                    if (_吸嘴有料信号.Any(x => x))
                    {
                        _step = 100;
                    }
                    else
                    {
                        _step = 10;
                    }
                }
            }
            #endregion
            #region 满盘收盘业务
            if (SignalOn(320))
            {
                _axisZ[0].Move(0, 30000);
                _axisZ[1].Move(0, 30000);
                _axisZ[2].Move(0, 30000);
                if (_axisZ[0].ArrivalLocation && _axisZ[1].ArrivalLocation && _axisZ[2].ArrivalLocation)
                {
                    NextStep();
                }
            }
            if (SignalOn(330))
            {
                if (_收盘升降.Reach_Open)
                {
                    _收盘升降.Auto_Open = false;
                    _收盘升降.Auto_Close = true;
                }
                else
                {
                    if (PointPositionMove(_推料盘位))
                    {
                        NextStep();
                    }
                }
            }
            if (SignalOn(340))
            {
                _推盘升降气缸.Auto_Open = true;
                _推盘升降气缸.Auto_Close = false;
                if (!_temporary.ShieldYAxisVariableSpeed)
                { StrokeMatchingSpeed(_axisEntityY.UnitConversion.ActualPosition - 10, 0.05, _axisEntityY, 0, 0); }
                if (_推盘升降气缸.Reach_Open)
                {
                    NextStep();
                }
            }
            if (SignalOn(350))
            {
                if (PointPositionMove(_收料盘位))
                {
                    _temporary.Status_Z轴.FullMaterial = false;
                    _temporary.Status_料盘固定.SafetyPosition = false;
                    _temporary.Status_料盘固定.DischargeComplete = true;
                    NextStep();
                }
            }
            if (SignalOn(360))
            {
                _推盘升降气缸.Auto_Close = true;
                _推盘升降气缸.Auto_Open = false;
                _收盘升降.Auto_Open = true;
                _收盘升降.Auto_Close = false;
                if (_推盘升降气缸.Reach_Close)
                {
                    NextStep();
                }
            }
            if (SignalOn(370))
            {
                if (_收盘升降.Reach_Open)
                {
                    _收盘升降.Auto_Open = false;
                    _收盘升降.Auto_Close = true;
                    _step = 10;
                }
            }
            #endregion
            if (_temporary.SystemStatus.ManualOperation)
            {
                #region 点位移动
                if (_temporary.JogMove)
                {
                    if (_pointname != _temporary.JogName)
                    {
                        _pointname = _temporary.JogName;
                        _log.Info($"点位 [{_pointname}]");
                    }
                    var ponitData = ((Parameter.AxisParameter)_axisParameter).PointPosition.FirstOrDefault(x => x.Name == _temporary.JogName);
                    if (PointPositionMove(ponitData))
                    {
                        _log.Info($"点位 [{_pointname}] 运动完成");
                        _temporary.JogMove = false;
                    }
                }
                #endregion
            }
        }

        public override void Resetting()
        {
            _temporary.JogName = string.Empty;
            _temporary.JogMove = false;
        }

        public override void SafeStop()
        {

        }

        private bool PointPositionMove(PointPositionInfoModel point)
        {
            if (point == null)
            {
                return true;
            }
            _axisX.Move(point.XPulse, 60000);
            _axisY.Move(point.YPulse, 60000);
            return _axisX.ArrivalLocation && _axisY.ArrivalLocation;
        }

        private bool PointPositionMove(long x_pulse, long y_pulse, bool bl = true)
        {
            _axisX.Move(x_pulse, 30000, bl: bl);
            _axisY.Move(y_pulse, 30000, bl: bl);
            return _axisX.ArrivalLocation && _axisY.ArrivalLocation;
        }

        private Parameter.Model.BackOrientationModel GetBackOrientation(Parameter.Model.BackOrientationModel[] orientationModels)
        {
            List<BackOrientationSort> sorts = new List<BackOrientationSort>();
            foreach (var item in orientationModels)
            {
                sorts.Add(new BackOrientationSort()
                {
                    Difference = Math.Round(Math.Abs(item.X - _axisEntityX.Status.CurrentPostion) + Math.Abs(item.Y - _axisEntityY.Status.CurrentPostion), 4, MidpointRounding.AwayFromZero),
                    Backs = item,
                });
            }
            sorts.Sort((x, y) => x.CompareTo(y));
            return sorts[0].Backs;
        }

        private void StrokeMatchingSpeed(double target_coordinate, double speed_percent, Axis axis, int min_travel_time, int acceleration_deceleration)
        {
            double difference = Math.Round(Math.Abs(target_coordinate - axis.UnitConversion.ActualPosition), 6, MidpointRounding.AwayFromZero);
            if (Math.Abs(difference) < 0.1)
            {
                difference = 1;
            }
            int max_pulse = ((int)(((3000 / 60) * axis.UnitConversion.CyclePulse) / 1000)) - 50;
            //double[] percent = new double[] { acceleration_deceleration * 0.1, 1.0 - (acceleration_deceleration * 0.1) };
            double start_speed = 0;

            if (difference >= axis.UnitConversion.WeeklyItinerary)
            {
                //满速度跑
                start_speed = max_pulse * speed_percent;
                axis.Parameter.Min_Vel = start_speed;
                axis.Parameter.Stop_Vel = start_speed;
                axis.Parameter.Max_Vel = max_pulse;
                axis.Parameter.STacc = (max_pulse - start_speed) / 160D;
                axis.Parameter.STdec = (max_pulse - start_speed) / 160D;
                //_log.Debug($"行程[{difference}]mm 动态设置速度==> 起始速度[{start_speed}]pulse/ms  最大速度[{max_pulse}]pulse/ms  加速度[{(max_pulse - start_speed) / 100D}]");
            }
            else
            {
                //百分比速度跑
                double max_pulse_percent = (DistanceToPulse(difference, axis) / axis.UnitConversion.CyclePulse) * max_pulse;
                start_speed = max_pulse_percent * 0.1;
                axis.Parameter.Min_Vel = start_speed;
                axis.Parameter.Stop_Vel = start_speed;
                axis.Parameter.Max_Vel = max_pulse_percent;
                axis.Parameter.STacc = (max_pulse_percent - start_speed) / 160D;
                axis.Parameter.STdec = (max_pulse_percent - start_speed) / 160D;
                //_log.Debug($"行程[{difference}]mm 动态设置速度==> 起始速度[{start_speed}]pulse/ms  最大速度[{max_pulse_percent}]pulse/ms  加速度[{(max_pulse_percent - start_speed) / 100D}]");
            }
        }
    }

    public class BackOrientationSort
    {
        public double Difference { get; set; }
        public Parameter.Model.BackOrientationModel Backs { get; set; }
        public int CompareTo(BackOrientationSort p)
        {
            int result = 0;
            if (Difference == p.Difference) result = 0;
            if (Difference > p.Difference) result = 1;
            if (Difference < p.Difference) result = -1;
            return result;
        }
    }
}